﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using Fulcrum.ControlGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.ControlGenerator
{
    [TestClass]
    public class TemplatePartXmlConfigurationTests
    {
        public TemplatePartXmlConfigurationTests()
        {
            // nothing
        }

        const string StandardTemplatePartXml = "<blah name='my name' type='my type' description='my description' optional='true'></blah>";
        const string DescriptionEmptyTemplatePartXml = "<blah name='my name' type='my type' description='' optional='true'></blah>";
        const string DescriptionMissingTemplatePartXml = "<blah name='my name' type='my type' optional='true'></blah>";
        const string NameEmptyTemplatePartXml = "<blah name='' type='my type' description='my description' optional='true'></blah>";
        const string NameMissingTemplatePartXml = "<blah type='my type' description='my description' optional='true'></blah>";
        const string TypeEmptyTemplatePartXml = "<blah name='my name' type='' description='my description' optional='true'></blah>";
        const string TypeMissingTemplatePartXml = "<blah name='my name' description='my description' optional='true'></blah>";
        const string OptionalFalseTemplatePartXml = "<blah name='my name' type='my type' description='my description' optional='false'></blah>";
        const string OptionalMissingTemplatePartXml = "<blah name='my name' type='my type' description='my description'></blah>";

        [TestMethod]
        public void TestReaderAdvancement()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardTemplatePartXml);

            Assert.IsTrue(xmlReader.IsStartElement());

            var config = new TemplatePartXmlConfiguration(xmlReader);

            Assert.IsFalse(xmlReader.IsStartElement());
        }

        [TestMethod]
        public void TestDescription()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.AreEqual("my description", config.Description);
        }

        [TestMethod]
        public void TestDescriptionEmpty()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(DescriptionEmptyTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.AreEqual("", config.Description);
        }

        [TestMethod]
        public void TestDescriptionMissing()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(DescriptionMissingTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.IsNull(config.Description);
        }

        [TestMethod]
        public void TestName()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.AreEqual("my name", config.Name);
        }

        [TestMethod]
        public void TestNameEmpty()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(NameEmptyTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.AreEqual("", config.Name);
        }

        [TestMethod]
        public void TestNameMissing()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(NameMissingTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.IsNull(config.Name);
        }

        [TestMethod]
        public void TestType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.AreEqual("my type", config.Type);
        }

        [TestMethod]
        public void TestTypeEmpty()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(TypeEmptyTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.AreEqual("", config.Type);
        }

        [TestMethod]
        public void TestTypeMissing()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(TypeMissingTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.IsNull(config.Type);
        }

        [TestMethod]
        public void TestOptionalTrue()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.IsTrue(config.Optional);
        }

        [TestMethod]
        public void TestOptionalFalse()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(OptionalFalseTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.IsFalse(config.Optional);
        }

        [TestMethod]
        public void TestOptionalMissing()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(OptionalMissingTemplatePartXml);

            var config = new TemplatePartXmlConfiguration(xmlReader);
            Assert.IsFalse(config.Optional);
        }
    }
}
